package com.tgy.clickhouse.service;

import com.tgy.clickhouse.dao.TestClickHouseMapper;
import com.tgy.clickhouse.entity.Alarm;
import com.tgy.clickhouse.exception.PredictionGlobalException;
import com.tgy.clickhouse.exception.error.BasicErrorType;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
@AllArgsConstructor
public class TestService {

    private final TestClickHouseMapper mapper;

    public List<String> query() {
        return mapper.selectCl();
    }

    public String insertAlarm(Alarm alarm) {
        try {
            mapper.insert(alarm);
        } catch (Exception e) {
            log.error("新增失败{}", e);
            return "失败";
        }
        return "成功";
    }

    public List<String> queryList() {
        //会自动处理，抛出异常
        int i  = 1/0;

        //验证数据的时候直接抛出一个异常就行了
        if(i == 0){
            throw new PredictionGlobalException(BasicErrorType.MEDIA_TYPE_NOT_SUPPORT_ERROR);
        }
        return mapper.queryList();
    }
}
